/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kwic;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Tom
 */
public class CircularShift {
    private ILineStorage lineStorage;
    private List<String> lines;
      

    public CircularShift(ILineStorage lineStorage) {
        this.lineStorage = lineStorage;
    }
    public void makeShift(){
          List<String> permutation=new ArrayList<>();
          lines=lineStorage.getLines();
           Iterator itL = lines.iterator();

        while (itL.hasNext()) {
            String currLine = (String) itL.next();
            String fieldLine[] = currLine.split(" ");
            for (int j = 0; j < fieldLine.length; j++) {
                String lastWord = fieldLine[fieldLine.length - 1];
                for (int k = fieldLine.length - 1; k > 0; k--) {
                    fieldLine[k] = fieldLine[k - 1];
                }
                fieldLine[0] = lastWord;
                String complete = "";
                for (int k = 0; k < fieldLine.length; k++) {
                    complete = complete.concat(fieldLine[k]);
                    complete = complete.concat(" ");
                }            
               permutation.add(complete);
            }
        }
        lines = permutation;
    }

    public List<String> getLines() {
        return lines;
    }

    public void setLines(List<String> lines) {
        this.lines = lines;
    }
    
}
